package com.xj.api.bussiness.personalInformationImg.web;

import com.xj.api.bussiness.personalInformationImg.service.ITbPersonalInformationImgService;
import com.xj.common.bussiness.personalInformationImg.entity.TbPersonalInformationImg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.xj.api.base.web.BaseController;
import com.xj.common.base.common.bean.AbstractBean;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * <p>
 * 个人信息的照片（如：身份证）  前端控制器
 * </p>
 *
 * @author Hmemb
 * @since 2018-01-27
 */
@RestController
@RequestMapping("personalInformationImg")
public class TbPersonalInformationImgController extends BaseController{
	
	@Autowired
	private ITbPersonalInformationImgService personalInformationImgService;
	
	@GetMapping
	@ApiOperation(value = "  列表", httpMethod = "GET", notes = "  列表")
	public AbstractBean personalInformationImgList(@RequestParam(required=false,defaultValue="0") Integer pageNum,@RequestParam(required=false,defaultValue="10") Integer pageSize){
		return json(personalInformationImgService.selectMapsPage(new Page<TbPersonalInformationImg>(pageNum, pageSize), new EntityWrapper<TbPersonalInformationImg>()));
	}
	
	@GetMapping("/{id}.auth")
	@ApiOperation(value = "  詳情", httpMethod = "GET", notes = "  詳情")
	public AbstractBean personalInformationImgContent(@PathVariable Integer id){
		return json(personalInformationImgService.selectById(id));
	}
	
	@PostMapping("save")
	@ApiOperation(value = "  新增", httpMethod = "POST", notes = " 新增")
	public AbstractBean add(TbPersonalInformationImg tbpersonalinformationimg){
		if(!personalInformationImgService.insertOrUpdate(tbpersonalinformationimg)){
		return error();
	    }
		return success();
	}
	@DeleteMapping("{id}/delete")
	@ApiOperation(value = "  删除", httpMethod = "POST", notes = " 删除")
    public AbstractBean delete(@PathVariable(required=true) Integer id) {	
		if(!personalInformationImgService.deleteById(id)){
		return error();
		}
		return success();
    }
	@PostMapping("getPersonalInformation")
	@ApiOperation(value = " 身份证号查询", httpMethod = "POST", notes = " 身份证号查询")
	public AbstractBean getPersonalInformation(TbPersonalInformationImg tbpersonalinformationImg){
			List<TbPersonalInformationImg> list=personalInformationImgService.getPersonalInformationImg(tbpersonalinformationImg);
			if(list!= null && list.size()>0){
				return SuccessMessage("用户存在","1");
			}else{
				return fail("用户不存在","0");
			}
	}
}
